package com.zelma.admin.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zelma.admin.entity.OrderEntity;
import com.zelma.admin.service.OrderService;
import com.zelma.common.utils.PageUtils;
import com.zelma.common.utils.R;



/**
 * 
 *
 * @author zelma
 * @email 1239115389@qq.com
 * @date 2022-01-06 16:54:29
 */
@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //订单数据同步ES接口
    @PostMapping("/eslist")
    public void eslist() throws IOException {

        orderService.eslist();
    }

    //订单查询接口
    @GetMapping("/findOrderInfo")
    public R findOrderInfo(@RequestParam(value = "resourceOrderId",defaultValue = "0") Integer resourceOrderId,
                           @RequestParam(value = "secondParam",defaultValue = "") String secondParam) throws IOException {

        List <OrderEntity> list = orderService.findOrderInfo(resourceOrderId, secondParam);

        return R.ok().put("list",list);
    }

    //根据订单编号删除记录
    @DeleteMapping("/removeByOrderId/{orderId}")
    public R removeByOrderId(@PathVariable("orderId") Integer orderId){
        OrderEntity orderEntity = orderService.getById(orderId);
        orderEntity.setTableLogicId(1);
        //执行逻辑删除
        boolean b = orderService.updateById(orderEntity);
        //判断是否删除成功
        if (b==true){
            //删除成功返回值
            return R.ok();
        }
        //删除失败返回值
        return R.error(500,"error");
    }

}
